dependent variable=        SGCFOUND 

===============================================================================
                     ** A Beta Model, Numerical Solution **                    
===============================================================================
 CML Version 1.0.0                                           6/20/01   8:16 pm
===============================================================================

return code =    0
normal convergence

Mean log-likelihood        0.505601
Number of cases     140

Covariance of the parameters computed by the following method:
Inverse of computed Hessian

Parameters    Estimates     Std. err.  Est./s.e.  Prob.    Gradient
------------------------------------------------------------------
const            1.1621        1.3555    0.857   0.1956      0.0000
SCOSTFAM        -0.0102        0.0448   -0.227   0.4103      0.0000
SBVALUE         -0.1993        0.0653   -3.053   0.0011      0.0000
SAPPS           -0.0965        0.0236   -4.083   0.0000      0.0000
SFLABOR         -0.0151        0.2161   -0.070   0.4722      0.0000
SECON            1.4060        0.5780    2.433   0.0075      0.0000
SDEMGOVT         0.2451        0.1991    1.231   0.1092      0.0000
YEAR1991         0.0086        0.1593    0.054   0.4785      0.0000
YEAR1992         0.0068        0.1850    0.037   0.4853      0.0000
const            1.3058        0.1138   11.477   0.0000      0.0000

Correlation matrix of the parameters
   1.000   0.048  -0.517   0.159  -0.871  -0.026  -0.517  -0.152  -0.118
   0.021
   0.048   1.000  -0.185  -0.333  -0.017  -0.402   0.182   0.118   0.217
   0.028
  -0.517  -0.185   1.000  -0.052   0.226   0.119   0.217   0.029   0.002
  -0.077
   0.159  -0.333  -0.052   1.000  -0.153   0.039  -0.213  -0.035  -0.106
  -0.134
  -0.871  -0.017   0.226  -0.153   1.000  -0.362   0.448   0.120   0.061
  -0.011
  -0.026  -0.402   0.119   0.039  -0.362   1.000  -0.103  -0.114  -0.097
   0.081
  -0.517   0.182   0.217  -0.213   0.448  -0.103   1.000   0.022   0.099
   0.074
  -0.152   0.118   0.029  -0.035   0.120  -0.114   0.022   1.000   0.419
  -0.005
  -0.118   0.217   0.002  -0.106   0.061  -0.097   0.099   0.419   1.000
   0.016
   0.021   0.028  -0.077  -0.134  -0.011   0.081   0.074  -0.005   0.016
   1.000

Number of iterations    4
Minutes to convergence     0.02607

        SCOSTFAM 
         SBVALUE 
           SAPPS 
         SFLABOR 
           SECON 
        SDEMGOVT 
        YEAR1991 
        YEAR1992 
   -0.0088630653     -0.021925494 
     -0.10395227      -0.23138288 
     -0.13320381      -0.41716141 
   -0.0027973145     -0.010032578 
      0.10524131       0.25343225 
     0.046223193      0.046676216 
    0.0015655032     0.0016593841 
    0.0012557013     0.0013173189 

        SCOSTFAM 
         SBVALUE 
           SAPPS 
         SFLABOR 
           SECON 
        SDEMGOVT 
        YEAR1991 
        YEAR1992 
   0.00092983728     0.0037950653     0.0019928370     0.0088742421 
     0.010323575     0.0033940147      0.022429590     0.0066563226 
     0.013024233     0.0030451410      0.014647794     0.0037679496 
   0.00038211595     0.0040605589     0.0010127036      0.013397912 
    -0.010459058     0.0042349281     -0.027821924     0.0098890847 
   -0.0045885650     0.0037946003    -0.0047615661     0.0039447520 
  -0.00031398190     0.0028351951   -0.00035997833     0.0030082946 
  -0.00018950516     0.0034532681   -0.00023434173     0.0036182332 
alpha= 2.72574 
beta= 0.96505 
ave mean= 0.73852 
ave var= 0.04117 
Valid cases:                   140      Dependent variable:                   Y
Missing cases:                   0      Deletion method:                   None
Total SS:                    4.526      Degrees of freedom:                 131
R-squared:                   0.167      Rbar-squared:                     0.116
Residual SS:                 3.772      Std error of est:                 0.170
F(8,131):                    3.272      Probability of F:                 0.002

                         Standard                 Prob   Standardized  Cor with
Variable     Estimate      Error      t-value     >|t|     Estimate    Dep Var
-------------------------------------------------------------------------------
CONSTANT     0.760709    0.221541    3.433713     0.001       ---         ---  
X1          -0.003132    0.007847   -0.399179     0.690   -0.039198   -0.084951
X2          -0.024531    0.011034   -2.223160     0.028   -0.184000   -0.220924
X3          -0.011903    0.004291   -2.773814     0.006   -0.236406   -0.239794
X4          -0.001757    0.037293   -0.047104     0.963   -0.004675   -0.059675
X5           0.131973    0.092615    1.424972     0.157    0.142027    0.081326
X6           0.074963    0.032808    2.284935     0.024    0.202942    0.237357
X7           0.006677    0.035444    0.188379     0.851    0.017442    0.066057
X8          -0.023593    0.035546   -0.663739     0.508   -0.062284   -0.076008

-0.01415 
-0.06640 
-0.08532 
-0.00169 
 0.05126 
 0.07324 
 0.00629 
-0.02248 
Valid cases:                   140      Dependent variable:                   Y
Missing cases:                   0      Deletion method:                   None
Total SS:                  773.140      Degrees of freedom:                 131
R-squared:                   0.150      Rbar-squared:                     0.098
Residual SS:               657.325      Std error of est:                 2.240
F(8,131):                    2.885      Probability of F:                 0.005

                         Standard                 Prob   Standardized  Cor with
Variable     Estimate      Error      t-value     >|t|     Estimate    Dep Var
-------------------------------------------------------------------------------
CONSTANT     1.652929    2.924486    0.565203     0.573       ---         ---  
X1          -0.066959    0.103580   -0.646451     0.519   -0.064114   -0.064513
X2          -0.392181    0.145660   -2.692444     0.008   -0.225069   -0.249211
X3          -0.153623    0.056645   -2.712029     0.008   -0.233452   -0.227774
X4           0.079811    0.492296    0.162119     0.871    0.016250    0.040393
X5           2.505707    1.222572    2.049537     0.042    0.206321    0.148140
X6           0.274658    0.433080    0.634196     0.527    0.056891    0.087789
X7           0.013062    0.467883    0.027918     0.978    0.002611    0.021516
X8          -0.075254    0.469227   -0.160378     0.873   -0.015200   -0.008314

-0.04394 
-0.15501 
-0.16084 
 0.01113 
 0.14198 
 0.03898 
 0.00179 
-0.01041 
extreme vals of y,Ey_beta,Ey_OLS,Ey_lnOLS
 0.22618  0.99990 
 0.44032  0.91995 
 0.52913  0.87232 
 0.34137  0.97931 
 percentage of OLS and lnOLS falling outside of [0,1]
 0.00000 
 0.00000 
 0.00000 
 0.00000 
Beta is better if rb/ro<1 1.09148 
beta mse= 0.02941 
ols mse= 0.02694 
Beta is better than logit trans if rb/ro<1 0.68550 

 0.35626  0.68565  0.67566  0.77198 
 0.44936  0.71929  0.69896  0.81693 
 0.31167  0.77201  0.70290  0.87348 
 0.68413  0.91995  0.87232  0.97700 
 0.81472  0.91002  0.81918  0.97846 
 0.60974  0.91834  0.84958  0.97931 
 0.22618  0.65523  0.62413  0.67295 
 0.87901  0.74034  0.75262  0.81839 
 0.76112  0.75904  0.76976  0.84606 
 0.49545  0.80138  0.77052  0.89229 
 0.47505  0.76734  0.70510  0.85552 
 0.48765  0.77201  0.71461  0.85977 
 0.49555  0.76882  0.68308  0.84796 
 0.86261  0.71399  0.67608  0.78427 
 0.90621  0.73457  0.69297  0.80506 
 0.70363  0.72503  0.65647  0.78755 
 0.69043  0.77344  0.69926  0.86287 
 0.66663  0.78444  0.71848  0.88815 
 0.70243  0.73462  0.65652  0.82558 
 0.99990  0.80157  0.72041  0.88542 
 0.99990  0.82058  0.74310  0.90940 
 0.99990  0.81674  0.71425  0.91008 
 0.99990  0.85079  0.80292  0.93356 
 0.89841  0.78116  0.77069  0.86721 
 0.91981  0.79864  0.79150  0.89030 
 0.88681  0.79229  0.75862  0.88119 
 0.99040  0.84630  0.81008  0.95013 
 0.98940  0.86185  0.81975  0.95173 
 0.99110  0.88230  0.81481  0.96554 
 0.84952  0.79347  0.73388  0.90109 
 0.92791  0.79954  0.74509  0.90988 
 0.89491  0.79464  0.71230  0.90337 
 0.67903  0.67997  0.70862  0.70354 
 0.71593  0.68579  0.71731  0.71288 
 0.58014  0.63081  0.61359  0.64287 
 0.57134  0.77355  0.72604  0.89393 
 0.50645  0.76148  0.71970  0.87195 
 0.37696  0.75368  0.68538  0.85524 
 0.91171  0.73869  0.69585  0.82755 
 0.65303  0.75323  0.71165  0.85130 
 0.79992  0.77050  0.69328  0.86451 
 0.62154  0.69783  0.72467  0.73956 
 0.74123  0.68582  0.72305  0.72014 
 0.55734  0.67825  0.68870  0.69426 
 0.58054  0.74290  0.75345  0.81819 
 0.49995  0.71399  0.69479  0.79954 
 0.71423  0.77026  0.74646  0.84443 
 0.52245  0.67707  0.65928  0.76260 
 0.63154  0.70878  0.68744  0.81678 
 0.69993  0.73265  0.67443  0.84061 
 0.43746  0.83215  0.80489  0.92230 
 0.46295  0.78684  0.72862  0.88704 
 0.46935  0.82627  0.77628  0.91135 
 0.54675  0.62541  0.62983  0.63996 
 0.57464  0.63053  0.63905  0.64926 
 0.60024  0.63556  0.61001  0.62796 
 0.46965  0.53861  0.58051  0.52275 
 0.44256  0.52562  0.57709  0.49792 
 0.44146  0.55497  0.56170  0.53707 
 0.81812  0.62898  0.65249  0.68004 
 0.74993  0.68482  0.73177  0.73033 
 0.99990  0.63734  0.62895  0.65924 
 0.71143  0.68071  0.66678  0.75191 
 0.72403  0.75776  0.72096  0.87157 
 0.73483  0.77872  0.74970  0.86403 
 0.89121  0.61533  0.62947  0.64929 
 0.92951  0.62581  0.63692  0.66838 
 0.38686  0.56143  0.57546  0.56130 
 0.73323  0.72583  0.68818  0.82495 
 0.66663  0.72981  0.69499  0.84112 
 0.59084  0.71971  0.65770  0.79183 
 0.55554  0.75632  0.73260  0.82081 
 0.66973  0.77374  0.75204  0.84048 
 0.78942  0.82276  0.71528  0.91315 
 0.99990  0.85937  0.78135  0.95548 
 0.99990  0.85429  0.78785  0.95515 
 0.99990  0.86200  0.76664  0.95774 
 0.70263  0.75516  0.69191  0.82802 
 0.73053  0.77477  0.74933  0.80262 
 0.75272  0.74739  0.65794  0.78554 
 0.64284  0.76280  0.76243  0.83664 
 0.64704  0.81984  0.80959  0.90885 
 0.69223  0.82742  0.78782  0.91235 
 0.56754  0.78535  0.76047  0.83124 
 0.55854  0.78810  0.76985  0.83666 
 0.52775  0.73808  0.65716  0.75313 
 0.80212  0.71651  0.68366  0.79744 
 0.79992  0.71943  0.69245  0.80793 
 0.80672  0.77167  0.74222  0.84731 
 0.56754  0.65401  0.64782  0.72873 
 0.43586  0.69129  0.67412  0.78573 
 0.34207  0.70929  0.65610  0.80802 
 0.65033  0.69920  0.67876  0.79710 
 0.65783  0.67906  0.66658  0.75126 
 0.56414  0.55833  0.57572  0.56783 
 0.72883  0.65623  0.64495  0.71150 
 0.95940  0.75627  0.75404  0.82066 
 0.79132  0.52013  0.59525  0.36144 
 0.89021  0.54262  0.57593  0.45195 
 0.93081  0.62408  0.67403  0.60662 
 0.91061  0.57791  0.57587  0.54218 
 0.81302  0.85453  0.82823  0.93689 
 0.69343  0.85306  0.83539  0.94170 
 0.81072  0.82556  0.73614  0.92511 
 0.76462  0.80225  0.78750  0.89260 
 0.76732  0.75538  0.76509  0.84852 
 0.82132  0.74272  0.72752  0.82820 
 0.55184  0.77137  0.72289  0.88128 
 0.79162  0.73142  0.70247  0.83093 
 0.79482  0.75937  0.69464  0.86695 
 0.76462  0.72763  0.69531  0.83440 
 0.64094  0.73683  0.70581  0.84908 
 0.79482  0.76367  0.69367  0.87279 
 0.93161  0.72698  0.74238  0.80093 
 0.97210  0.74580  0.76140  0.82763 
 0.93611  0.73566  0.72517  0.80623 
 0.99990  0.85575  0.83600  0.94759 
 0.99990  0.85799  0.84581  0.95141 
 0.73323  0.85727  0.81493  0.94697 
 0.64994  0.53849  0.59117  0.51519 
 0.58734  0.56919  0.61005  0.55330 
 0.62594  0.58361  0.58686  0.55212 
 0.47535  0.65956  0.64300  0.71280 
 0.60284  0.72599  0.69134  0.83691 
 0.53325  0.64247  0.61404  0.72716 
 0.84262  0.87517  0.84722  0.96088 
 0.85181  0.87573  0.85500  0.96221 
 0.84532  0.84616  0.75150  0.94846 
 0.48665  0.44032  0.57479  0.34137 
 0.56794  0.47320  0.59797  0.41588 
 0.57944  0.45302  0.55879  0.37404 
 0.83922  0.76352  0.77175  0.84770 
 0.84372  0.76024  0.77570  0.84486 
 0.88361  0.74844  0.73812  0.81984 
 0.56674  0.61377  0.63269  0.69064 
 0.53265  0.61891  0.63682  0.67356 
 0.55554  0.66805  0.63083  0.73830 
 0.59034  0.58480  0.59517  0.59899 
 0.75572  0.61179  0.60853  0.62255 
 0.57884  0.49838  0.52913  0.47285 

code used to generate the above results:

library cml;
#include cml.ext;
CMLset;

__title=" ** A Beta Model, Numerical Solution **";
dta="/home/gov/faculty/ppaolino/parr/soss";
let dep=sgcfound;
let ind=scostfam sbvalue sapps sflabor secon sdemgovt year1991 year1992;
let indV=0;
let sel=0;

c={1,0,0,0,0,0,0,0,0};

if ind==0;
   vars=dep;
   elseif indV==0; 
   vars=dep|ind;    
   else;
   vars=dep|ind|indV;
endif;

dataset=listw(dta,vars,sel);

stval=   1.1621|
	-0.0102|
	-0.1993|
	-0.0965|
	-0.0151|
	 1.4060|
	 0.2451|
	 0.0086|
	 0.0068|
	 1.3058;
	 
proc psi(x);
  local p;
  x=x+6;
  p=1/(x.*x);
  p=(((0.004166666666667*p-0.003968253986254).*p+
      0.008333333333333).*p-0.083333333333333).*p;
  p=p+ln(x)-0.5/x-1/(x-1)-1/(x-2)-1/(x-3)-1/(x-4)-1/(x-5)-1/(x-6);
retp(p);
endp;

proc gradproc(theta,ds);
    local y,one,x,z,be,h,xb,zh,zh1,e,per1,gr1,gr2,grad;
    y=(ds[.,1])*100/10001;
    one=ones(rows(ds),1);
if ind==0;
    x=one;
    else;
    x=one~ds[.,2:rows(ind)+1];
endif;
if indV==0;
    z=one;	     
    else;
    z=one~ds[.,cols(ds)-rows(indV)+1:cols(ds)];
endif;		     
    be=theta[1:cols(x),1];
    h=trimr(theta,rows(be),0);      
    xb=exp(x*be);
    zh=exp(z*h);
    zh1=zh+1;
    e=xb./(1+xb);
    per1=(-x.*e+x.*(e^2)).*zh1;

    gr1=psi(e.*zh1+(1-e).*zh1-1).*(x.*e.*zh1-(e^2).*zh1.*x+per1)-
        psi(e.*zh1-e).*(x.*e.*zh1-(e^2).*zh1.*x-x.*e+(e^2).*x)-
        psi((1-e).*zh1-1+e).*(per1+x.*e-(e^2).*x)+
        (x.*e.*zh1-(e^2).*zh1.*x-x.*e+(e^2).*x).*ln(y)+
        (per1+x.*e-(e^2).*x).*ln(1-y);
    gr2=psi(e.*zh1+(1-e).*zh1-1).*(e.*z.*zh+(1-e).*z.*zh)-
        (psi(e.*zh1-e).*xb.*z.*zh)./(1+xb)-
        psi((1-e).*zh1-1+e).*(1-e).*z.*zh+xb.*z.*zh.*ln(y)./(1+xb)+
        (1-e).*z.*zh.*ln(1-y);
    grad=gr1~gr2;
    retp(grad);endp;

proc loglik(theta,ds);
    local y,one,x,z,be,h,xb,zh,e,v,a,b,llik,ds1;
		     
    y=(ds[.,1])*100/10001;
    one=ones(rows(ds),1);
if ind==0;
    x=one;
    else;
    x=one~ds[.,2:rows(ind)+1];
endif;
if indV==0;
    z=one;	     
    else;
    z=one~ds[.,cols(ds)-rows(indV)+1:cols(ds)];
endif;		     
    be=theta[1:cols(x),1];
    h=trimr(theta,rows(be),0);      
    xb=exp(x*be);
    zh=exp(z*h);
    e=xb./(1+xb);
    v=e.*(1-e).*(1/(zh+1));
    a=((e^2).*(1-e))./v-e;
    b=(e.*(1-e)^2)./v-(1-e);
    llik=lng(a+b)-lng(a)-lng(b)+(a-1).*ln(y)+(b-1).*ln(1-y);
    retp(llik);endp;

    if ind==0;
      _cml_ParNames="const"|"const";
    elseif indV==0;
      _cml_ParNames="const"|ind|"const";
    else;
      _cml_ParNames="const"|ind|"const"|indV;
    endif;

/* _cml_GradCheck=1;
_cml_GradProc=&gradproc;  */
_cml_Options = { none }; 
_cml_DirTol=0.00001; 

t=dta $+ dep $+ ".dir.out"; 
output file=^t on; 
    print "dependent variable=" ;; $dep; 
    {b,logl,g,vc,ret}=CMLprt(CML(dataset,0,&loglik,stval));
@ cond(_cml_FinalHess); @

/* set ind and indV matrices */
y=(dataset[.,1])*100/10001;
one=ones(rows(dataset),1);

if ind==0;
  x=one;
  else;
  x=ones(rows(dataset),1)~dataset[.,2:rows(ind)+1]; 
endif;

if indV==0;
  z=one;
  else;
  z=ones(rows(dataset),1)~dataset[.,cols(dataset)-rows(indV)+1:cols(dataset)]; 
endif;		     

/* get predicted values of y */
    bb=trimr(b,0,1);
    if indV/=0;
       bb=trimr(b,0,rows(indV)+1);
    endif;
    xb=exp(x*bb);
    eyb=xb./(1+xb);

/* set descriptives for x and z */
meanx=meanc(x);  @ these are k1X1 vectors @
stdx=stdc(x);	
minx=minc(x);	
maxx=maxc(x);	

meanz=meanc(z);

/* create switching parameter */

if ind/=0;
sw=zeros(1,cols(x)-1)|eye(cols(x)-1);
xl=meanx-stdx.*sw;           @ these are kXk-1 vectors @
xh=meanx+stdx.*sw;       
xmin=meanx.*(1-sw)+minx.*sw;  
xmax=meanx.*(1-sw)+maxx.*sw;
endif;

/* generate the parameter vectors */
    be=b[1:cols(x),.];      @ chop off parms for alpha (k1X1) @
    h=trimr(b,rows(be),0);  @ chop off parms for beta (k2X1) @

/* get predicted means */

    em=(exp(meanx'*be)./(1+exp(meanx'*be)))'; @ these are nX1 vectors @

    if ind/=0;
      emin=(exp(xmin'*be)./(1+exp(xmin'*be)))';
      emax=(exp(xmax'*be)./(1+exp(xmax'*be)))';
      el=(exp(xl'*be)./(1+exp(xl'*be)))';
      eh=(exp(xh'*be)./(1+exp(xh'*be)))';
    endif;
  
/* get first differences for the mean */
    if ind/=0;
    fdm2=eh-el;
    fdmm=emax-emin;
    endif;
    
/* get predicted variances for variables affecting the mean */

  betasim=rndmn(b,vc,1000);
  bs=betasim[.,1:cols(x)];
  hs=betasim[.,cols(x)+1:cols(betasim)];

  ml=(exp(bs*xl)./(1+exp(bs*xl)));
  mh=(exp(bs*xh)./(1+exp(bs*xh)));
  m0=(exp(bs*xmin)./(1+exp(bs*xmin)));
  m1=(exp(bs*xmax)./(1+exp(bs*xmax)));
  
@  if indv/=0; @
    j=1; i=1; hx=zeros(1000,rows(c)); 
    do until j>rows(c);
       if c[j]==1;
	 hx[.,j]=hx[.,j]+hs[.,i];
	 i=i+1;
       endif;
    j=j+1;
    endo;
@  endif; @

    dm=(1/(exp(meanz'*h)+1));
    vm=em.*(1-em).*dm;

@  if indV/=0; @
      dmin=(1/(exp(hx*xmin)+1));
      dmax=(1/(exp(hx*xmax)+1));
      dl=(1/(exp(hx*xl)+1));
      dh=(1/(exp(hx*xh)+1));
      vmin=m0.*(1-m0).*dmin;
      vmax=m1.*(1-m1).*dmax;
      vl=ml.*(1-ml).*dl;
      vh=mh.*(1-mh).*dh;

      fdv2=vh-vl;
      fdvm=vmax-vmin;
@  endif; @

  if ind/=0;
    print $ind;; meanc(fdm2)~meanc(fdmm);
  endif;
  
@  if indV/=0; @
    print $ind;; meanc(fdv2)~stdc(fdv2)~meanc(fdvm)~stdc(fdvm);
@  endif; @
    
format /rd 8,5;

print "alpha=";; ((em^2).*(1-em))./vm-em;
print "beta=";; (em.*(1-em)^2)./vm-(1-em);
alp=((em^2).*(1-em))./vm-em;
bet=(em.*(1-em)^2)./vm-(1-em);
print "ave mean=";; alp/(alp+bet);
print "ave var=";; alp*bet/((alp+bet)^2*(alp+bet+1)); 

/* run ols */

{ vnam,m,bols,stb,vcols,stderr,sigma,cx,rsq,resid,dbw } = ols(0,y,x);

/* generate first differences for ols */
  olsl=xl'*bols;
  olsh=xh'*bols;
  
  olsh-olsl;

/* run ols with logit transformation*/

yt=ln(y./(1-y));

{ vnam,m,bolsl,stbl,vcols,stderrl,sigma,cx,rsq,resid,dbw } = ols(0,yt,x);

/* generate first differences for ols */
  olsl=(exp(xl'*bolsl))./(1+exp(xl'*bolsl));
  olsh=(exp(xh'*bolsl))./(1+exp(xh'*bolsl)); 
  
  olsh-olsl;

  ely=(exp(x*bolsl))./(1+exp(x*bolsl));
  
let pe=perinst;
if rows(y)==50 and stof(dep)/=stof(pe);
/* run ols for logged model */
  
let depl=lpemp;
let indl=ltask lwealth rights lelite lcol;
varsl=depl|indl;
dataset2=listw(dta,varsl,sel);
ly=(dataset2[.,1]);
lx=ones(rows(ly),1)~(dataset2[.,2:cols(dataset2)]);

{ lvnam,lm,lbols,lstb,lvcols,lstderr,lsigma,lcx,lrsq,lresid,ldbw } = ols(0,ly,lx);


/* set descriptives for x and z */
meanlx=meanc(lx);  @ these are k1X1 vectors @
stdlx=stdc(lx);	
minlx=minc(lx);	
maxlx=maxc(lx);	

/* create switching parameter */

if ind/=0;
lsw=zeros(1,cols(lx)-1)|eye(cols(lx)-1);
lxl=meanlx-stdlx.*lsw;           @ these are kXk-1 vectors @
lxh=meanlx+stdlx.*lsw;       
lxmin=meanlx.*(1-lsw)+minlx.*lsw;  
lxmax=meanlx.*(1-lsw)+maxlx.*lsw;
endif;

/* generate first differences for logged ols */

  lolsl=(exp(lxl'*lbols)-1)*100/10101;
  lolsh=(exp(lxh'*lbols)-1)*100/10101;
  
  lolsh-lolsl; 

/* get predicted data */
predly=lx*lbols;
predyl=(exp(predly)-1)*100/10101;
yadj=(exp(ly)-1)*100/10101;
minc(predyl)~maxc(predyl);
minc(yadj)~maxc(yadj);
msel=sumc((yadj-predyl)^2)/rows(y); 
endif;

/* compare mse of y */
mseb=sumc((y-eyb)^2)/rows(y);
mseo=sumc((y-x*bols)^2)/rows(y);
mset=sumc((y-ely)^2)/rows(y);

print "extreme vals of y,Ey_beta,Ey_OLS,Ey_lnOLS";
minc(y)~maxc(y);
minc(eyb)~maxc(eyb);
minc(x*bols)~maxc(x*bols);
minc(ely)~maxc(ely);
if rows(y)==50 and stof(dep)/=stof(pe);
minc(predyl)~maxc(predyl);
endif;
print " percentage of OLS and lnOLS falling outside of [0,1]";
sumc(x*bols.>1)/rows(y);
sumc(x*bols.<0)/rows(y);
sumc(ely.>1)/rows(y);
sumc(ely.<0)/rows(y);
if rows(y)==50 and stof(dep)/=stof(pe);
sumc(predyl.>1)/rows(y);
sumc(predyl.<0)/rows(y); 
endif;

rbro=mseb/mseo;
print "Beta is better if rb/ro<1";;rbro;
print "beta mse=";;mseb;
print "ols mse=";;mseo;
rbrt=mseb/mset;
print "Beta is better than logit trans if rb/ro<1";;rbrt;
if rows(y)==50 and stof(dep)/=stof(pe);
rbrl=mseb/msel; 
print "Beta is better if rb/rl<1";;rbrl; 
endif;

y~eyb~(x*bols)~ely;
output off;

dependent variable=        SGCFOUND 

===============================================================================
                     ** A Beta Model, Numerical Solution **                    
===============================================================================
 CML Version 1.0.0                                           6/20/01   8:25 pm
===============================================================================

return code =    0
normal convergence

Mean log-likelihood        0.599029
Number of cases     140

Covariance of the parameters computed by the following method:
Inverse of computed Hessian

Parameters    Estimates     Std. err.  Est./s.e.  Prob.    Gradient
------------------------------------------------------------------
const            1.7915        1.2987    1.379   0.0839      0.0000
SCOSTFAM         0.0443        0.0347    1.278   0.1007      0.0000
SBVALUE         -0.1248        0.0630   -1.981   0.0238      0.0000
SAPPS           -0.0723        0.0138   -5.239   0.0000      0.0000
SFLABOR         -0.2695        0.2198   -1.226   0.1101      0.0000
SECON            1.3099        0.5181    2.528   0.0057      0.0000
SDEMGOVT         0.3120        0.1790    1.743   0.0407      0.0000
YEAR1991         0.0969        0.1631    0.594   0.2762      0.0000
YEAR1992         0.1171        0.1653    0.709   0.2393      0.0000
const           -0.4073        0.6613   -0.616   0.2690      0.0000
SBVALUE          0.2147        0.1092    1.966   0.0247      0.0000
SAPPS            0.1831        0.0349    5.249   0.0000      0.0000

Correlation matrix of the parameters
   1.000   0.078  -0.341   0.334  -0.901   0.018  -0.557   0.020   0.006
  -0.103   0.103   0.088
   0.078   1.000   0.001  -0.235  -0.201  -0.108   0.038   0.104   0.328
  -0.190   0.176   0.174
  -0.341   0.001   1.000   0.069   0.143  -0.292   0.136   0.085   0.073
  -0.524   0.513   0.063
   0.334  -0.235   0.069   1.000  -0.239  -0.306  -0.569   0.078  -0.095
  -0.335   0.308  -0.046
  -0.901  -0.201   0.143  -0.239   1.000  -0.291   0.442  -0.085  -0.096
   0.138  -0.109  -0.254
   0.018  -0.108  -0.292  -0.306  -0.291   1.000   0.140  -0.098  -0.112
   0.454  -0.494   0.257
  -0.557   0.038   0.136  -0.569   0.442   0.140   1.000  -0.114   0.015
   0.258  -0.266   0.097
   0.020   0.104   0.085   0.078  -0.085  -0.098  -0.114   1.000   0.521
  -0.177   0.166   0.109
   0.006   0.328   0.073  -0.095  -0.096  -0.112   0.015   0.521   1.000
  -0.222   0.206   0.179
  -0.103  -0.190  -0.524  -0.335   0.138   0.454   0.258  -0.177  -0.222
   1.000  -0.971  -0.178
   0.103   0.176   0.513   0.308  -0.109  -0.494  -0.266   0.166   0.206
  -0.971   1.000   0.016
   0.088   0.174   0.063  -0.046  -0.254   0.257   0.097   0.109   0.179
  -0.178   0.016   1.000

Number of iterations    10
Minutes to convergence     0.09312

        SCOSTFAM 
         SBVALUE 
           SAPPS 
         SFLABOR 
           SECON 
        SDEMGOVT 
        YEAR1991 
        YEAR1992 
     0.039633825      0.094557974 
    -0.066839950      -0.15117781 
     -0.10237067      -0.31384707 
    -0.051227347      -0.18610555 
      0.10056051       0.24593601 
     0.060328659      0.060739540 
     0.018092598      0.019045206 
     0.022093909      0.022994622 

        SCOSTFAM 
         SBVALUE 
           SAPPS 
         SFLABOR 
           SECON 
        SDEMGOVT 
        YEAR1991 
        YEAR1992 
   -0.0032698615     0.0027036480    -0.0080855426     0.0065974782 
    -0.012030212      0.011709598     -0.027360600      0.027483942 
    -0.029909445     0.0088106850     -0.049571207     0.0092093018 
    0.0043491810     0.0036133804      0.013025883      0.010018461 
   -0.0086327408     0.0033539945     -0.023590978     0.0080903676 
   -0.0051308061     0.0029831557    -0.0053430838     0.0031285706 
   -0.0015312670     0.0025291013    -0.0016638116     0.0027125268 
   -0.0018774350     0.0025912435    -0.0020120640     0.0027572144 
alpha= 3.11587 
beta= 1.16480 
ave mean= 0.72789 
ave var= 0.03751 
Valid cases:                   140      Dependent variable:                   Y
Missing cases:                   0      Deletion method:                   None
Total SS:                    4.526      Degrees of freedom:                 131
R-squared:                   0.167      Rbar-squared:                     0.116
Residual SS:                 3.772      Std error of est:                 0.170
F(8,131):                    3.272      Probability of F:                 0.002

                         Standard                 Prob   Standardized  Cor with
Variable     Estimate      Error      t-value     >|t|     Estimate    Dep Var
-------------------------------------------------------------------------------
CONSTANT     0.760709    0.221541    3.433713     0.001       ---         ---  
X1          -0.003132    0.007847   -0.399179     0.690   -0.039198   -0.084951
X2          -0.024531    0.011034   -2.223160     0.028   -0.184000   -0.220924
X3          -0.011903    0.004291   -2.773814     0.006   -0.236406   -0.239794
X4          -0.001757    0.037293   -0.047104     0.963   -0.004675   -0.059675
X5           0.131973    0.092615    1.424972     0.157    0.142027    0.081326
X6           0.074963    0.032808    2.284935     0.024    0.202942    0.237357
X7           0.006677    0.035444    0.188379     0.851    0.017442    0.066057
X8          -0.023593    0.035546   -0.663739     0.508   -0.062284   -0.076008

-0.01415 
-0.06640 
-0.08532 
-0.00169 
 0.05126 
 0.07324 
 0.00629 
-0.02248 
Valid cases:                   140      Dependent variable:                   Y
Missing cases:                   0      Deletion method:                   None
Total SS:                  773.140      Degrees of freedom:                 131
R-squared:                   0.150      Rbar-squared:                     0.098
Residual SS:               657.325      Std error of est:                 2.240
F(8,131):                    2.885      Probability of F:                 0.005

                         Standard                 Prob   Standardized  Cor with
Variable     Estimate      Error      t-value     >|t|     Estimate    Dep Var
-------------------------------------------------------------------------------
CONSTANT     1.652929    2.924486    0.565203     0.573       ---         ---  
X1          -0.066959    0.103580   -0.646451     0.519   -0.064114   -0.064513
X2          -0.392181    0.145660   -2.692444     0.008   -0.225069   -0.249211
X3          -0.153623    0.056645   -2.712029     0.008   -0.233452   -0.227774
X4           0.079811    0.492296    0.162119     0.871    0.016250    0.040393
X5           2.505707    1.222572    2.049537     0.042    0.206321    0.148140
X6           0.274658    0.433080    0.634196     0.527    0.056891    0.087789
X7           0.013062    0.467883    0.027918     0.978    0.002611    0.021516
X8          -0.075254    0.469227   -0.160378     0.873   -0.015200   -0.008314

-0.04394 
-0.15501 
-0.16084 
 0.01113 
 0.14198 
 0.03898 
 0.00179 
-0.01041 
extreme vals of y,Ey_beta,Ey_OLS,Ey_lnOLS
 0.22618  0.99990 
 0.54002  0.91322 
 0.52913  0.87232 
 0.34137  0.97931 
 percentage of OLS and lnOLS falling outside of [0,1]
 0.00000 
 0.00000 
 0.00000 
 0.00000 
Beta is better if rb/ro<1 1.05156 
beta mse= 0.02833 
ols mse= 0.02694 
Beta is better than logit trans if rb/ro<1 0.66043 

 0.35626  0.66207  0.67566  0.77198 
 0.44936  0.71237  0.69896  0.81693 
 0.31167  0.74697  0.70290  0.87348 
 0.68413  0.91322  0.87232  0.97700 
 0.81472  0.89105  0.81918  0.97846 
 0.60974  0.90380  0.84958  0.97931 
 0.22618  0.68896  0.62413  0.67295 
 0.87901  0.72497  0.75262  0.81839 
 0.76112  0.76010  0.76976  0.84606 
 0.49545  0.78261  0.77052  0.89229 
 0.47505  0.75809  0.70510  0.85552 
 0.48765  0.78056  0.71461  0.85977 
 0.49555  0.77841  0.68308  0.84796 
 0.86261  0.70295  0.67608  0.78427 
 0.90621  0.75665  0.69297  0.80506 
 0.70363  0.71860  0.65647  0.78755 
 0.69043  0.75945  0.69926  0.86287 
 0.66663  0.75576  0.71848  0.88815 
 0.70243  0.71371  0.65652  0.82558 
 0.99990  0.79351  0.72041  0.88542 
 0.99990  0.81790  0.74310  0.90940 
 0.99990  0.79282  0.71425  0.91008 
 0.99990  0.83823  0.80292  0.93356 
 0.89841  0.76067  0.77069  0.86721 
 0.91981  0.78631  0.79150  0.89030 
 0.88681  0.77387  0.75862  0.88119 
 0.99040  0.80373  0.81008  0.95013 
 0.98940  0.85468  0.81975  0.95173 
 0.99110  0.86203  0.81481  0.96554 
 0.84952  0.73900  0.73388  0.90109 
 0.92791  0.75483  0.74509  0.90988 
 0.89491  0.74126  0.71230  0.90337 
 0.67903  0.69293  0.70862  0.70354 
 0.71593  0.72071  0.71731  0.71288 
 0.58014  0.65008  0.61359  0.64287 
 0.57134  0.68116  0.72604  0.89393 
 0.50645  0.70775  0.71970  0.87195 
 0.37696  0.69503  0.68538  0.85524 
 0.91171  0.70305  0.69585  0.82755 
 0.65303  0.72542  0.71165  0.85130 
 0.79992  0.73069  0.69328  0.86451 
 0.62154  0.71284  0.72467  0.73956 
 0.74123  0.72297  0.72305  0.72014 
 0.55734  0.72139  0.68870  0.69426 
 0.58054  0.74005  0.75345  0.81819 
 0.49995  0.70574  0.69479  0.79954 
 0.71423  0.77066  0.74646  0.84443 
 0.52245  0.64629  0.65928  0.76260 
 0.63154  0.66254  0.68744  0.81678 
 0.69993  0.66882  0.67443  0.84061 
 0.43746  0.79139  0.80489  0.92230 
 0.46295  0.75428  0.72862  0.88704 
 0.46935  0.79616  0.77628  0.91135 
 0.54675  0.65026  0.62983  0.63996 
 0.57464  0.67290  0.63905  0.64926 
 0.60024  0.68553  0.61001  0.62796 
 0.46965  0.54896  0.58051  0.52275 
 0.44256  0.56660  0.57709  0.49792 
 0.44146  0.59341  0.56170  0.53707 
 0.81812  0.59184  0.65249  0.68004 
 0.74993  0.68998  0.73177  0.73033 
 0.99990  0.64581  0.62895  0.65924 
 0.71143  0.64026  0.66678  0.75191 
 0.72403  0.69987  0.72096  0.87157 
 0.73483  0.75232  0.74970  0.86403 
 0.89121  0.59262  0.62947  0.64929 
 0.92951  0.62512  0.63692  0.66838 
 0.38686  0.57078  0.57546  0.56130 
 0.73323  0.64138  0.68818  0.82495 
 0.66663  0.61589  0.69499  0.84112 
 0.59084  0.69651  0.65770  0.79183 
 0.55554  0.77537  0.73260  0.82081 
 0.66973  0.80210  0.75204  0.84048 
 0.78942  0.81098  0.71528  0.91315 
 0.99990  0.78972  0.78135  0.95548 
 0.99990  0.78035  0.78785  0.95515 
 0.99990  0.78761  0.76664  0.95774 
 0.70263  0.76746  0.69191  0.82802 
 0.73053  0.84551  0.74933  0.80262 
 0.75272  0.80343  0.65794  0.78554 
 0.64284  0.75779  0.76243  0.83664 
 0.64704  0.81204  0.80959  0.90885 
 0.69223  0.81773  0.78782  0.91235 
 0.56754  0.83264  0.76047  0.83124 
 0.55854  0.84358  0.76985  0.83666 
 0.52775  0.81304  0.65716  0.75313 
 0.80212  0.67923  0.68366  0.79744 
 0.79992  0.69140  0.69245  0.80793 
 0.80672  0.75485  0.74222  0.84731 
 0.56754  0.62748  0.64782  0.72873 
 0.43586  0.67504  0.67412  0.78573 
 0.34207  0.68061  0.65610  0.80802 
 0.65033  0.65134  0.67876  0.79710 
 0.65783  0.68866  0.66658  0.75126 
 0.56414  0.58634  0.57572  0.56783 
 0.72883  0.68479  0.64495  0.71150 
 0.95940  0.80213  0.75404  0.82066 
 0.79132  0.66821  0.59525  0.36144 
 0.89021  0.64235  0.57593  0.45195 
 0.93081  0.70480  0.67403  0.60662 
 0.91061  0.64282  0.57587  0.54218 
 0.81302  0.84505  0.82823  0.93689 
 0.69343  0.84159  0.83539  0.94170 
 0.81072  0.79767  0.73614  0.92511 
 0.76462  0.77020  0.78750  0.89260 
 0.76732  0.73256  0.76509  0.84852 
 0.82132  0.71161  0.72752  0.82820 
 0.55184  0.71878  0.72289  0.88128 
 0.79162  0.70014  0.70247  0.83093 
 0.79482  0.70588  0.69464  0.86695 
 0.76462  0.65788  0.69531  0.83440 
 0.64094  0.68050  0.70581  0.84908 
 0.79482  0.70445  0.69367  0.87279 
 0.93161  0.71894  0.74238  0.80093 
 0.97210  0.74579  0.76140  0.82763 
 0.93611  0.73215  0.72517  0.80623 
 0.99990  0.80141  0.83600  0.94759 
 0.99990  0.80975  0.84581  0.95141 
 0.73323  0.81079  0.81493  0.94697 
 0.64994  0.54519  0.59117  0.51519 
 0.58734  0.60091  0.61005  0.55330 
 0.62594  0.62048  0.58686  0.55212 
 0.47535  0.64166  0.64300  0.71280 
 0.60284  0.68005  0.69134  0.83691 
 0.53325  0.60076  0.61404  0.72716 
 0.84262  0.82709  0.84722  0.96088 
 0.85181  0.83162  0.85500  0.96221 
 0.84532  0.78229  0.75150  0.94846 
 0.48665  0.54002  0.57479  0.34137 
 0.56794  0.57319  0.59797  0.41588 
 0.57944  0.54863  0.55879  0.37404 
 0.83922  0.77329  0.77175  0.84770 
 0.84372  0.78274  0.77570  0.84486 
 0.88361  0.77875  0.73812  0.81984 
 0.56674  0.54498  0.63269  0.69064 
 0.53265  0.59927  0.63682  0.67356 
 0.55554  0.63925  0.63083  0.73830 
 0.59034  0.61427  0.59517  0.59899 
 0.75572  0.67671  0.60853  0.62255 
 0.57884  0.54715  0.52913  0.47285 

code used to generate the above results:

library cml;
#include cml.ext;
CMLset;

__title=" ** A Beta Model, Numerical Solution **";
dta="/home/gov/faculty/ppaolino/parr/soss";
let dep=sgcfound;
let ind=scostfam sbvalue sapps sflabor secon sdemgovt year1991 year1992;
let indV=sbvalue sapps;
let sel=0;

c={1,0,1,1,0,0,0,0,0};

if ind==0;
   vars=dep;
   elseif indV==0; 
   vars=dep|ind;    
   else;
   vars=dep|ind|indV;
endif;

dataset=listw(dta,vars,sel);

stval=   1.1621|
	-0.0102|
	-0.1993|
	-0.0965|
	-0.0151|
	 1.4060|
	 0.2451|
	 0.0086|
	 0.0068|
	 1.3058|
	-0.0155|
	-0.0834;
	 
proc psi(x);
  local p;
  x=x+6;
  p=1/(x.*x);
  p=(((0.004166666666667*p-0.003968253986254).*p+
      0.008333333333333).*p-0.083333333333333).*p;
  p=p+ln(x)-0.5/x-1/(x-1)-1/(x-2)-1/(x-3)-1/(x-4)-1/(x-5)-1/(x-6);
retp(p);
endp;

proc gradproc(theta,ds);
    local y,one,x,z,be,h,xb,zh,zh1,e,per1,gr1,gr2,grad;
    y=(ds[.,1])*100/10001;
    one=ones(rows(ds),1);
if ind==0;
    x=one;
    else;
    x=one~ds[.,2:rows(ind)+1];
endif;
if indV==0;
    z=one;	     
    else;
    z=one~ds[.,cols(ds)-rows(indV)+1:cols(ds)];
endif;		     
    be=theta[1:cols(x),1];
    h=trimr(theta,rows(be),0);      
    xb=exp(x*be);
    zh=exp(z*h);
    zh1=zh+1;
    e=xb./(1+xb);
    per1=(-x.*e+x.*(e^2)).*zh1;

    gr1=psi(e.*zh1+(1-e).*zh1-1).*(x.*e.*zh1-(e^2).*zh1.*x+per1)-
        psi(e.*zh1-e).*(x.*e.*zh1-(e^2).*zh1.*x-x.*e+(e^2).*x)-
        psi((1-e).*zh1-1+e).*(per1+x.*e-(e^2).*x)+
        (x.*e.*zh1-(e^2).*zh1.*x-x.*e+(e^2).*x).*ln(y)+
        (per1+x.*e-(e^2).*x).*ln(1-y);
    gr2=psi(e.*zh1+(1-e).*zh1-1).*(e.*z.*zh+(1-e).*z.*zh)-
        (psi(e.*zh1-e).*xb.*z.*zh)./(1+xb)-
        psi((1-e).*zh1-1+e).*(1-e).*z.*zh+xb.*z.*zh.*ln(y)./(1+xb)+
        (1-e).*z.*zh.*ln(1-y);
    grad=gr1~gr2;
    retp(grad);endp;

proc loglik(theta,ds);
    local y,one,x,z,be,h,xb,zh,e,v,a,b,llik,ds1;
		     
    y=(ds[.,1])*100/10001;
    one=ones(rows(ds),1);
if ind==0;
    x=one;
    else;
    x=one~ds[.,2:rows(ind)+1];
endif;
if indV==0;
    z=one;	     
    else;
    z=one~ds[.,cols(ds)-rows(indV)+1:cols(ds)];
endif;		     
    be=theta[1:cols(x),1];
    h=trimr(theta,rows(be),0);      
    xb=exp(x*be);
    zh=exp(z*h);
    e=xb./(1+xb);
    v=e.*(1-e).*(1/(zh+1));
    a=((e^2).*(1-e))./v-e;
    b=(e.*(1-e)^2)./v-(1-e);
    llik=lng(a+b)-lng(a)-lng(b)+(a-1).*ln(y)+(b-1).*ln(1-y);
    retp(llik);endp;

    if ind==0;
      _cml_ParNames="const"|"const";
    elseif indV==0;
      _cml_ParNames="const"|ind|"const";
    else;
      _cml_ParNames="const"|ind|"const"|indV;
    endif;

/* _cml_GradCheck=1;
_cml_GradProc=&gradproc;  */
_cml_Options = { none }; 
_cml_DirTol=0.00001; 

t=dta $+ dep $+ ".dir.out"; 
output file=^t on; 
    print "dependent variable=" ;; $dep; 
    {b,logl,g,vc,ret}=CMLprt(CML(dataset,0,&loglik,stval));
@ cond(_cml_FinalHess); @

/* set ind and indV matrices */
y=(dataset[.,1])*100/10001;
one=ones(rows(dataset),1);

if ind==0;
  x=one;
  else;
  x=ones(rows(dataset),1)~dataset[.,2:rows(ind)+1]; 
endif;

if indV==0;
  z=one;
  else;
  z=ones(rows(dataset),1)~dataset[.,cols(dataset)-rows(indV)+1:cols(dataset)]; 
endif;		     

/* get predicted values of y */
    bb=trimr(b,0,1);
    if indV/=0;
       bb=trimr(b,0,rows(indV)+1);
    endif;
    xb=exp(x*bb);
    eyb=xb./(1+xb);

/* set descriptives for x and z */
meanx=meanc(x);  @ these are k1X1 vectors @
stdx=stdc(x);	
minx=minc(x);	
maxx=maxc(x);	

meanz=meanc(z);

/* create switching parameter */

if ind/=0;
sw=zeros(1,cols(x)-1)|eye(cols(x)-1);
xl=meanx-stdx.*sw;           @ these are kXk-1 vectors @
xh=meanx+stdx.*sw;       
xmin=meanx.*(1-sw)+minx.*sw;  
xmax=meanx.*(1-sw)+maxx.*sw;
endif;

/* generate the parameter vectors */
    be=b[1:cols(x),.];      @ chop off parms for alpha (k1X1) @
    h=trimr(b,rows(be),0);  @ chop off parms for beta (k2X1) @

/* get predicted means */

    em=(exp(meanx'*be)./(1+exp(meanx'*be)))'; @ these are nX1 vectors @

    if ind/=0;
      emin=(exp(xmin'*be)./(1+exp(xmin'*be)))';
      emax=(exp(xmax'*be)./(1+exp(xmax'*be)))';
      el=(exp(xl'*be)./(1+exp(xl'*be)))';
      eh=(exp(xh'*be)./(1+exp(xh'*be)))';
    endif;
  
/* get first differences for the mean */
    if ind/=0;
    fdm2=eh-el;
    fdmm=emax-emin;
    endif;
    
/* get predicted variances for variables affecting the mean */

  betasim=rndmn(b,vc,1000);
  bs=betasim[.,1:cols(x)];
  hs=betasim[.,cols(x)+1:cols(betasim)];

  ml=(exp(bs*xl)./(1+exp(bs*xl)));
  mh=(exp(bs*xh)./(1+exp(bs*xh)));
  m0=(exp(bs*xmin)./(1+exp(bs*xmin)));
  m1=(exp(bs*xmax)./(1+exp(bs*xmax)));
  
@  if indv/=0; @
    j=1; i=1; hx=zeros(1000,rows(c)); 
    do until j>rows(c);
       if c[j]==1;
	 hx[.,j]=hx[.,j]+hs[.,i];
	 i=i+1;
       endif;
    j=j+1;
    endo;
@  endif; @

    dm=(1/(exp(meanz'*h)+1));
    vm=em.*(1-em).*dm;

@  if indV/=0; @
      dmin=(1/(exp(hx*xmin)+1));
      dmax=(1/(exp(hx*xmax)+1));
      dl=(1/(exp(hx*xl)+1));
      dh=(1/(exp(hx*xh)+1));
      vmin=m0.*(1-m0).*dmin;
      vmax=m1.*(1-m1).*dmax;
      vl=ml.*(1-ml).*dl;
      vh=mh.*(1-mh).*dh;

      fdv2=vh-vl;
      fdvm=vmax-vmin;
@  endif; @

  if ind/=0;
    print $ind;; meanc(fdm2)~meanc(fdmm);
  endif;
  
@  if indV/=0; @
    print $ind;; meanc(fdv2)~stdc(fdv2)~meanc(fdvm)~stdc(fdvm);
@  endif; @
    
format /rd 8,5;

print "alpha=";; ((em^2).*(1-em))./vm-em;
print "beta=";; (em.*(1-em)^2)./vm-(1-em);
alp=((em^2).*(1-em))./vm-em;
bet=(em.*(1-em)^2)./vm-(1-em);
print "ave mean=";; alp/(alp+bet);
print "ave var=";; alp*bet/((alp+bet)^2*(alp+bet+1)); 

/* run ols */

{ vnam,m,bols,stb,vcols,stderr,sigma,cx,rsq,resid,dbw } = ols(0,y,x);

/* generate first differences for ols */
  olsl=xl'*bols;
  olsh=xh'*bols;
  
  olsh-olsl;

/* run ols with logit transformation*/

yt=ln(y./(1-y));

{ vnam,m,bolsl,stbl,vcols,stderrl,sigma,cx,rsq,resid,dbw } = ols(0,yt,x);

/* generate first differences for ols */
  olsl=(exp(xl'*bolsl))./(1+exp(xl'*bolsl));
  olsh=(exp(xh'*bolsl))./(1+exp(xh'*bolsl)); 
  
  olsh-olsl;

  ely=(exp(x*bolsl))./(1+exp(x*bolsl));
  
let pe=perinst;
if rows(y)==50 and stof(dep)/=stof(pe);
/* run ols for logged model */
  
let depl=lpemp;
let indl=ltask lwealth rights lelite lcol;
varsl=depl|indl;
dataset2=listw(dta,varsl,sel);
ly=(dataset2[.,1]);
lx=ones(rows(ly),1)~(dataset2[.,2:cols(dataset2)]);

{ lvnam,lm,lbols,lstb,lvcols,lstderr,lsigma,lcx,lrsq,lresid,ldbw } = ols(0,ly,lx);


/* set descriptives for x and z */
meanlx=meanc(lx);  @ these are k1X1 vectors @
stdlx=stdc(lx);	
minlx=minc(lx);	
maxlx=maxc(lx);	

/* create switching parameter */

if ind/=0;
lsw=zeros(1,cols(lx)-1)|eye(cols(lx)-1);
lxl=meanlx-stdlx.*lsw;           @ these are kXk-1 vectors @
lxh=meanlx+stdlx.*lsw;       
lxmin=meanlx.*(1-lsw)+minlx.*lsw;  
lxmax=meanlx.*(1-lsw)+maxlx.*lsw;
endif;

/* generate first differences for logged ols */

  lolsl=(exp(lxl'*lbols)-1)*100/10101;
  lolsh=(exp(lxh'*lbols)-1)*100/10101;
  
  lolsh-lolsl; 

/* get predicted data */
predly=lx*lbols;
predyl=(exp(predly)-1)*100/10101;
yadj=(exp(ly)-1)*100/10101;
minc(predyl)~maxc(predyl);
minc(yadj)~maxc(yadj);
msel=sumc((yadj-predyl)^2)/rows(y); 
endif;

/* compare mse of y */
mseb=sumc((y-eyb)^2)/rows(y);
mseo=sumc((y-x*bols)^2)/rows(y);
mset=sumc((y-ely)^2)/rows(y);

print "extreme vals of y,Ey_beta,Ey_OLS,Ey_lnOLS";
minc(y)~maxc(y);
minc(eyb)~maxc(eyb);
minc(x*bols)~maxc(x*bols);
minc(ely)~maxc(ely);
if rows(y)==50 and stof(dep)/=stof(pe);
minc(predyl)~maxc(predyl);
endif;
print " percentage of OLS and lnOLS falling outside of [0,1]";
sumc(x*bols.>1)/rows(y);
sumc(x*bols.<0)/rows(y);
sumc(ely.>1)/rows(y);
sumc(ely.<0)/rows(y);
if rows(y)==50 and stof(dep)/=stof(pe);
sumc(predyl.>1)/rows(y);
sumc(predyl.<0)/rows(y); 
endif;

rbro=mseb/mseo;
print "Beta is better if rb/ro<1";;rbro;
print "beta mse=";;mseb;
print "ols mse=";;mseo;
rbrt=mseb/mset;
print "Beta is better than logit trans if rb/ro<1";;rbrt;
if rows(y)==50 and stof(dep)/=stof(pe);
rbrl=mseb/msel; 
print "Beta is better if rb/rl<1";;rbrl; 
endif;

y~eyb~(x*bols)~ely;
output off;

dependent variable=        SGCFOUND 

===============================================================================
                     ** A Beta Model, Numerical Solution **                    
===============================================================================
 CML Version 1.0.0                                           6/20/01   8:51 pm
===============================================================================

return code =    0
normal convergence

Mean log-likelihood        0.606017
Number of cases     140

Covariance of the parameters computed by the following method:
Inverse of computed Hessian

Parameters    Estimates     Std. err.  Est./s.e.  Prob.    Gradient
------------------------------------------------------------------
const            1.9573        1.3184    1.485   0.0688      0.0000
SCOSTFAM         0.0387        0.0354    1.092   0.1374      0.0000
SBVALUE         -0.1285        0.0634   -2.027   0.0213      0.0000
SAPPS           -0.0712        0.0136   -5.255   0.0000      0.0000
SFLABOR         -0.2732        0.2225   -1.228   0.1098      0.0000
SECON            1.1892        0.5318    2.236   0.0127      0.0000
SDEMGOVT         0.3435        0.1768    1.943   0.0260      0.0000
YEAR1991         0.1366        0.1650    0.828   0.2038      0.0000
YEAR1992         0.1472        0.1668    0.883   0.1887      0.0000
const           -0.7202        0.7174   -1.004   0.1577      0.0000
SBVALUE          0.2533        0.1156    2.191   0.0142      0.0000
SAPPS            0.1745        0.0356    4.899   0.0000      0.0000
SDEMGOVT         0.3477        0.2475    1.405   0.0801      0.0000

Correlation matrix of the parameters
   1.000   0.091  -0.349   0.325  -0.896  -0.001  -0.549   0.026   0.017
  -0.118   0.117   0.047   0.100
   0.091   1.000  -0.021  -0.243  -0.211  -0.093  -0.006   0.085   0.304
  -0.157   0.154   0.215  -0.111
  -0.349  -0.021   1.000   0.108   0.139  -0.248   0.098   0.080   0.056
  -0.493   0.496   0.079  -0.040
   0.325  -0.243   0.108   1.000  -0.226  -0.333  -0.544   0.087  -0.082
  -0.344   0.336  -0.125   0.076
  -0.896  -0.211   0.139  -0.226   1.000  -0.290   0.450  -0.072  -0.093
   0.134  -0.111  -0.233  -0.017
  -0.001  -0.093  -0.248  -0.333  -0.290   1.000   0.130  -0.135  -0.126
   0.470  -0.507   0.295  -0.185
  -0.549  -0.006   0.098  -0.544   0.450   0.130   1.000  -0.100   0.007
   0.224  -0.253   0.060   0.106
   0.026   0.085   0.080   0.087  -0.072  -0.135  -0.100   1.000   0.535
  -0.233   0.214   0.073   0.179
   0.017   0.304   0.056  -0.082  -0.093  -0.126   0.007   0.535   1.000
  -0.262   0.240   0.169   0.135
  -0.118  -0.157  -0.493  -0.344   0.134   0.470   0.224  -0.233  -0.262
   1.000  -0.972  -0.109  -0.337
   0.117   0.154   0.496   0.336  -0.111  -0.507  -0.253   0.214   0.240
  -0.972   1.000  -0.023   0.257
   0.047   0.215   0.079  -0.125  -0.233   0.295   0.060   0.073   0.169
  -0.109  -0.023   1.000  -0.183
   0.100  -0.111  -0.040   0.076  -0.017  -0.185   0.106   0.179   0.135
  -0.337   0.257  -0.183   1.000

Number of iterations    10
Minutes to convergence     0.14733

        SCOSTFAM 
         SBVALUE 
           SAPPS 
         SFLABOR 
           SECON 
        SDEMGOVT 
        YEAR1991 
        YEAR1992 
     0.034439173      0.082479261 
    -0.068551825      -0.15492509 
     -0.10052519      -0.30856681 
    -0.051730542      -0.18800981 
     0.090957905       0.22565063 
     0.066133241      0.066463220 
     0.025401361      0.026652272 
     0.027663587      0.028725838 

        SCOSTFAM 
         SBVALUE 
           SAPPS 
         SFLABOR 
           SECON 
        SDEMGOVT 
        YEAR1991 
        YEAR1992 
   -0.0029936526     0.0026704810    -0.0073942804     0.0065100189 
    -0.014795428      0.011405928     -0.033461764      0.027009228 
    -0.027953109     0.0082817140     -0.047445063     0.0087359734 
    0.0043051213     0.0033879235      0.013080836     0.0095552924 
   -0.0075463299     0.0033933575     -0.020842244     0.0085159869 
    -0.015988177     0.0080730805     -0.015712618     0.0076783005 
   -0.0023130874     0.0025504725    -0.0025036989     0.0027511617 
   -0.0025137349     0.0027438308    -0.0026926098     0.0029359009 
alpha= 3.16351 
beta= 1.17201 
ave mean= 0.72967 
ave var= 0.03697 
Valid cases:                   140      Dependent variable:                   Y
Missing cases:                   0      Deletion method:                   None
Total SS:                    4.526      Degrees of freedom:                 131
R-squared:                   0.167      Rbar-squared:                     0.116
Residual SS:                 3.772      Std error of est:                 0.170
F(8,131):                    3.272      Probability of F:                 0.002

                         Standard                 Prob   Standardized  Cor with
Variable     Estimate      Error      t-value     >|t|     Estimate    Dep Var
-------------------------------------------------------------------------------
CONSTANT     0.760709    0.221541    3.433713     0.001       ---         ---  
X1          -0.003132    0.007847   -0.399179     0.690   -0.039198   -0.084951
X2          -0.024531    0.011034   -2.223160     0.028   -0.184000   -0.220924
X3          -0.011903    0.004291   -2.773814     0.006   -0.236406   -0.239794
X4          -0.001757    0.037293   -0.047104     0.963   -0.004675   -0.059675
X5           0.131973    0.092615    1.424972     0.157    0.142027    0.081326
X6           0.074963    0.032808    2.284935     0.024    0.202942    0.237357
X7           0.006677    0.035444    0.188379     0.851    0.017442    0.066057
X8          -0.023593    0.035546   -0.663739     0.508   -0.062284   -0.076008

-0.01415 
-0.06640 
-0.08532 
-0.00169 
 0.05126 
 0.07324 
 0.00629 
-0.02248 
Valid cases:                   140      Dependent variable:                   Y
Missing cases:                   0      Deletion method:                   None
Total SS:                  773.140      Degrees of freedom:                 131
R-squared:                   0.150      Rbar-squared:                     0.098
Residual SS:               657.325      Std error of est:                 2.240
F(8,131):                    2.885      Probability of F:                 0.005

                         Standard                 Prob   Standardized  Cor with
Variable     Estimate      Error      t-value     >|t|     Estimate    Dep Var
-------------------------------------------------------------------------------
CONSTANT     1.652929    2.924486    0.565203     0.573       ---         ---  
X1          -0.066959    0.103580   -0.646451     0.519   -0.064114   -0.064513
X2          -0.392181    0.145660   -2.692444     0.008   -0.225069   -0.249211
X3          -0.153623    0.056645   -2.712029     0.008   -0.233452   -0.227774
X4           0.079811    0.492296    0.162119     0.871    0.016250    0.040393
X5           2.505707    1.222572    2.049537     0.042    0.206321    0.148140
X6           0.274658    0.433080    0.634196     0.527    0.056891    0.087789
X7           0.013062    0.467883    0.027918     0.978    0.002611    0.021516
X8          -0.075254    0.469227   -0.160378     0.873   -0.015200   -0.008314

-0.04394 
-0.15501 
-0.16084 
 0.01113 
 0.14198 
 0.03898 
 0.00179 
-0.01041 
extreme vals of y,Ey_beta,Ey_OLS,Ey_lnOLS
 0.22618  0.99990 
 0.53847  0.90376 
 0.52913  0.87232 
 0.34137  0.97931 
 percentage of OLS and lnOLS falling outside of [0,1]
 0.00000 
 0.00000 
 0.00000 
 0.00000 
Beta is better if rb/ro<1 1.04907 
beta mse= 0.02827 
ols mse= 0.02694 
Beta is better than logit trans if rb/ro<1 0.65886 

 0.35626  0.66569  0.67566  0.77198 
 0.44936  0.72277  0.69896  0.81693 
 0.31167  0.75493  0.70290  0.87348 
 0.68413  0.90376  0.87232  0.97700 
 0.81472  0.88096  0.81918  0.97846 
 0.60974  0.89759  0.84958  0.97931 
 0.22618  0.69010  0.62413  0.67295 
 0.87901  0.73344  0.75262  0.81839 
 0.76112  0.77505  0.76976  0.84606 
 0.49545  0.79553  0.77052  0.89229 
 0.47505  0.74771  0.70510  0.85552 
 0.48765  0.77813  0.71461  0.85977 
 0.49555  0.77472  0.68308  0.84796 
 0.86261  0.69336  0.67608  0.78427 
 0.90621  0.75518  0.69297  0.80506 
 0.70363  0.71399  0.65647  0.78755 
 0.69043  0.74275  0.69926  0.86287 
 0.66663  0.74998  0.71848  0.88815 
 0.70243  0.70636  0.65652  0.82558 
 0.99990  0.77938  0.72041  0.88542 
 0.99990  0.81206  0.74310  0.90940 
 0.99990  0.78697  0.71425  0.91008 
 0.99990  0.84377  0.80292  0.93356 
 0.89841  0.76302  0.77069  0.86721 
 0.91981  0.79636  0.79150  0.89030 
 0.88681  0.78378  0.75862  0.88119 
 0.99040  0.80210  0.81008  0.95013 
 0.98940  0.85338  0.81975  0.95173 
 0.99110  0.86100  0.81481  0.96554 
 0.84952  0.73476  0.73388  0.90109 
 0.92791  0.75872  0.74509  0.90988 
 0.89491  0.74421  0.71230  0.90337 
 0.67903  0.69490  0.70862  0.70354 
 0.71593  0.73052  0.71731  0.71288 
 0.58014  0.65287  0.61359  0.64287 
 0.57134  0.68132  0.72604  0.89393 
 0.50645  0.71300  0.71970  0.87195 
 0.37696  0.69852  0.68538  0.85524 
 0.91171  0.69777  0.69585  0.82755 
 0.65303  0.72895  0.71165  0.85130 
 0.79992  0.73216  0.69328  0.86451 
 0.62154  0.71906  0.72467  0.73956 
 0.74123  0.73659  0.72305  0.72014 
 0.55734  0.73352  0.68870  0.69426 
 0.58054  0.74696  0.75345  0.81819 
 0.49995  0.71338  0.69479  0.79954 
 0.71423  0.78137  0.74646  0.84443 
 0.52245  0.64182  0.65928  0.76260 
 0.63154  0.66918  0.68744  0.81678 
 0.69993  0.67445  0.67443  0.84061 
 0.43746  0.78988  0.80489  0.92230 
 0.46295  0.75362  0.72862  0.88704 
 0.46935  0.79981  0.77628  0.91135 
 0.54675  0.64334  0.62983  0.63996 
 0.57464  0.67552  0.63905  0.64926 
 0.60024  0.68466  0.61001  0.62796 
 0.46965  0.53847  0.58051  0.52275 
 0.44256  0.56507  0.57709  0.49792 
 0.44146  0.59060  0.56170  0.53707 
 0.81812  0.59886  0.65249  0.68004 
 0.74993  0.70977  0.73177  0.73033 
 0.99990  0.65716  0.62895  0.65924 
 0.71143  0.63671  0.66678  0.75191 
 0.72403  0.70738  0.72096  0.87157 
 0.73483  0.76237  0.74970  0.86403 
 0.89121  0.58854  0.62947  0.64929 
 0.92951  0.62873  0.63692  0.66838 
 0.38686  0.57434  0.57546  0.56130 
 0.73323  0.63476  0.68818  0.82495 
 0.66663  0.61673  0.69499  0.84112 
 0.59084  0.69592  0.65770  0.79183 
 0.55554  0.76579  0.73260  0.82081 
 0.66973  0.80041  0.75204  0.84048 
 0.78942  0.80422  0.71528  0.91315 
 0.99990  0.78146  0.78135  0.95548 
 0.99990  0.78164  0.78785  0.95515 
 0.99990  0.78801  0.76664  0.95774 
 0.70263  0.75422  0.69191  0.82802 
 0.73053  0.84270  0.74933  0.80262 
 0.75272  0.79488  0.65794  0.78554 
 0.64284  0.76222  0.76243  0.83664 
 0.64704  0.82193  0.80959  0.90885 
 0.69223  0.82690  0.78782  0.91235 
 0.56754  0.82852  0.76047  0.83124 
 0.55854  0.84566  0.76985  0.83666 
 0.52775  0.80736  0.65716  0.75313 
 0.80212  0.67393  0.68366  0.79744 
 0.79992  0.69550  0.69245  0.80793 
 0.80672  0.76298  0.74222  0.84731 
 0.56754  0.62462  0.64782  0.72873 
 0.43586  0.68110  0.67412  0.78573 
 0.34207  0.68605  0.65610  0.80802 
 0.65033  0.65055  0.67876  0.79710 
 0.65783  0.69330  0.66658  0.75126 
 0.56414  0.59249  0.57572  0.56783 
 0.72883  0.68133  0.64495  0.71150 
 0.95940  0.80988  0.75404  0.82066 
 0.79132  0.67366  0.59525  0.36144 
 0.89021  0.62843  0.57593  0.45195 
 0.93081  0.71098  0.67403  0.60662 
 0.91061  0.64018  0.57587  0.54218 
 0.81302  0.84644  0.82823  0.93689 
 0.69343  0.84942  0.83539  0.94170 
 0.81072  0.80094  0.73614  0.92511 
 0.76462  0.77271  0.78750  0.89260 
 0.76732  0.74610  0.76509  0.84852 
 0.82132  0.72436  0.72752  0.82820 
 0.55184  0.71922  0.72289  0.88128 
 0.79162  0.70759  0.70247  0.83093 
 0.79482  0.71405  0.69464  0.86695 
 0.76462  0.65761  0.69531  0.83440 
 0.64094  0.68827  0.70581  0.84908 
 0.79482  0.71061  0.69367  0.87279 
 0.93161  0.72621  0.74238  0.80093 
 0.97210  0.76054  0.76140  0.82763 
 0.93611  0.74577  0.72517  0.80623 
 0.99990  0.80502  0.83600  0.94759 
 0.99990  0.82006  0.84581  0.95141 
 0.73323  0.81958  0.81493  0.94697 
 0.64994  0.54270  0.59117  0.51519 
 0.58734  0.60602  0.61005  0.55330 
 0.62594  0.62281  0.58686  0.55212 
 0.47535  0.63071  0.64300  0.71280 
 0.60284  0.68244  0.69134  0.83691 
 0.53325  0.60248  0.61404  0.72716 
 0.84262  0.82772  0.84722  0.96088 
 0.85181  0.83812  0.85500  0.96221 
 0.84532  0.78436  0.75150  0.94846 
 0.48665  0.53978  0.57479  0.34137 
 0.56794  0.58390  0.59797  0.41588 
 0.57944  0.55788  0.55879  0.37404 
 0.83922  0.78332  0.77175  0.84770 
 0.84372  0.79917  0.77570  0.84486 
 0.88361  0.79419  0.73812  0.81984 
 0.56674  0.54462  0.63269  0.69064 
 0.53265  0.60534  0.63682  0.67356 
 0.55554  0.64238  0.63083  0.73830 
 0.59034  0.59767  0.59517  0.59899 
 0.75572  0.66603  0.60853  0.62255 
 0.57884  0.53962  0.52913  0.47285 
